﻿@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "gvEditing";
            settings.KeyFieldName = "IdBarrio";
            settings.CallbackRouteValues = new { Controller = "Barrio", Action = "EditBarrioPartial" };
            settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Barrio", Action = "EditBarrioAddNewPartial" };
            settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Barrio", Action = "EditBarrioUpdatePartial" };
            settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Barrio", Action = "EditBarrioDeletePartial" };
            settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
            
            
            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 600;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
            settings.SettingsPager.FirstPageButton.Visible = true;
            settings.SettingsPager.LastPageButton.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };

            
            settings.Settings.ShowFilterRow = true;
            settings.Settings.ShowFilterRowMenu = true;
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowClearFilterButton = true;
            
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowNewButtonInHeader = ViewBag.PermisoCreate;
            settings.CommandColumn.ShowEditButton = ViewBag.PermisoEdit;
            settings.CommandColumn.ShowDeleteButton = ViewBag.PermisoDelete;

            settings.Columns.Add("Nombre");

            settings.Columns.Add(
               column =>
               {
                   column.FieldName = "Localidad.IdLocalidad";
                   column.Caption = "Localidad";

                   column.ColumnType = MVCxGridViewColumnType.ComboBox;
                   var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                   comboBoxProperties.DataSource = ViewBag.Localidad;
                   comboBoxProperties.TextField = "Nombre";
                   comboBoxProperties.ValueField = "IdLocalidad";
                   comboBoxProperties.ValueType = typeof(int);
                   comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
                   comboBoxProperties.ValidationSettings.CausesValidation = false;
               });


            //settings.Columns.Add(column =>
            //{
            //    column.FieldName = "Localidad.Nombre";
            //    column.Caption = "Localidad";
            //});

            //settings.Columns.Add(column =>
            //{
            //    column.FieldName = "Localidad.Provincia.Nombre";
            //    column.Caption = "Provincia";
            //});

            settings.Columns.Add("Localidad.Provincia.Nombre").EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;

            //settings.Columns.Add(
            //    column =>
            //    {
            //        column.FieldName = "Localidad.Provincia.IdProvincia";
            //        column.Caption = "Provincia";

            //        column.ColumnType = MVCxGridViewColumnType.ComboBox;
            //        var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
            //        comboBoxProperties.DataSource = ViewBag.Provincia;
            //        comboBoxProperties.TextField = "Nombre";
            //        comboBoxProperties.ValueField = "IdProvincia";
            //        comboBoxProperties.ValueType = typeof(int);
            //        comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
            //        comboBoxProperties.ValidationSettings.CausesValidation = false;
            //    });
            
           
        });

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()



















